package org.zhadoop.stream.cql.hooks;

import org.zhadoop.stream.cql.DriverContext;
import org.zhadoop.stream.cql.exception.SemanticAnalyzerException;
import org.zhadoop.stream.cql.semanticanalyzer.analyzecontext.AnalyzeContext;
import org.zhadoop.stream.cql.semanticanalyzer.analyzecontext.CreateStreamAnalyzeContext;
import org.zhadoop.stream.cql.semanticanalyzer.parser.context.CreateInputStatementContext;
import org.zhadoop.stream.cql.semanticanalyzer.parser.context.ParseContext;

/**
 * schema 语义前后的钩子
 * @author zwd
 *
 */
public class CreateStreamAnalyzehook implements SemanticAnalyzeHook {

	@Override
	public boolean validate(ParseContext parseContext) throws SemanticAnalyzerException {
		return (parseContext instanceof CreateInputStatementContext)
				|| (parseContext instanceof CreateInputStatementContext);
	}

	@Override
	public void preAnalyze(DriverContext context, ParseContext parseContext) throws SemanticAnalyzerException {
		
	}

	@Override
	public void postAnalyze(DriverContext context, AnalyzeContext analyzeContext) throws SemanticAnalyzerException {
		CreateStreamAnalyzeContext csContext = (CreateStreamAnalyzeContext) analyzeContext;
		context.addSchema(csContext.getSchema());
	}


}
